<!--
 * @Author: Dorange.Wang
 * @Date: 2021-11-12 10:48:01
 * @LastEditors: your name
 * @LastEditTime: 2021-11-15 13:44:01
 * @Description: file content
-->
<template>
  <el-dialog
    :visible="showVisible"
    center
    :show-close="false"
    width="600px">
    <div class="b g3 f16 tl" slot="title">
      <div class="ks-row-between pl15 pr15">
        <span>{{$t('sys.save_to_history')}}</span>
        <span
          class="el-icon-close g9 f26 poi"
          @click="showVisible = false"
        ></span>
      </div>
    </div>

    <el-form
      class="pl30 pr30"
      :model="formData"
      ref="form"
    >
      <el-form-item
        prop="title"
        :rules="[
          { required: true, message: $t('sys.enter_record_title'), trigger: 'change' },
        ]"
      >
        <el-input
          v-model="formData.title"
          style="width: 100%"
          :placeholder="$t('sys.enter_record_title')"
          :maxlength="200"
          show-word-limit
        />
      </el-form-item>

    </el-form>

    <div slot="footer" class="tr">
      <el-button @click="showVisible = false">{{$t('sys.cancel')}}</el-button>
      <el-button type="primary" @click="submit">{{$t('sys.confirm')}}</el-button>
    </div>
  </el-dialog>
</template>

<script>
// 
import { putHmmodelMove } from '@/apis/paas/HmModelController.js'
import { postHmwebsql } from '@/apis/paas/HmWebSqlController.js'

export default {
  data () {
    return {
      showVisible: false,
      options: {},
      formData: {}
    }
  },

  methods: {
    open (options = {}) {
      this.showVisible = true
      this.options = { ...options }
      this.formData = {}
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
      })
    },

    async submit () {
      try {
        await this.$refs.form.validate()
        const { title } = this.formData
        const { sqlContent } = this.options

        const params = {
          title, dml: sqlContent
        }
        postHmwebsql(params).then(res => {
          this.showVisible = false
        })
      } catch (error) {
        console.log(error)
      }
    }
  }
}
</script>

<style lang="scss" scoped></style>
